import java.util.HashSet;
import java.util.Random;

public class MathProblemsGenerator {
    public static void main(String[] args) {
        int[] exerciseSizes = {5, 6, 7, 23, 24, 25, 59, 60, 61, 119, 120};
        int n = 0;

        for (int size : exerciseSizes) {
            Random random = new Random();
            HashSet<String> usedExercises = new HashSet<>();
            int count = 0;
            n++;
            System.out.println("第" + n + "组");
            while (usedExercises.size() < size) {
                boolean isAddition = random.nextBoolean();
                if (isAddition) {
                    String additionExercise = generateAdditionExercise(random);
                    if (!usedExercises.contains(additionExercise)) {
                        usedExercises.add(additionExercise);
                        System.out.printf("%-15s", additionExercise);
                        count++;
                        if (count % 6 == 0) {
                            System.out.println();
                        }
                    }
                } else {
                    String subtractionExercise = generateSubtractionExercise(random);
                    if (!usedExercises.contains(subtractionExercise)) {
                        usedExercises.add(subtractionExercise);
                        System.out.printf("%-15s", subtractionExercise);
                        count++;
                        if (count % 6 == 0) {
                            System.out.println();
                        }
                    }
                }
            }
            System.out.println();
        }

        // 调用测试类
        MathProblemsTest.runTests();
    }

    public static String generateAdditionExercise(Random random) {
        int num1 = random.nextInt(100);
        int num2 = random.nextInt(100 - num1);
        int sum = num1 + num2;
        return num1 + " + " + num2 + " = " + sum;
    }

    public static String generateSubtractionExercise(Random random) {
        int num1 = random.nextInt(100);
        int num2 = random.nextInt(num1 + 1);
        int difference = num1 - num2;
        return num1 + " - " + num2 + " = " + difference;
    }
}